﻿using System;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Tokens
{
    struct FormulaWriteContext
    {
        private readonly BinaryWriter _writer;
        private readonly FormulaReadContextType _type;

        public FormulaWriteContext(BinaryWriter writer, FormulaReadContextType type)
        {
            _writer = writer;
            _type = type;
        }

        public BinaryWriter Writer
        {
            get {
                return _writer;
            }
        }

        public FormulaReadContextType Type
        {
            get { return _type; }
        }

        public void WriteByte(byte value)
        {
            Writer.Write(value);
        }

        public void WriteUInt16(ushort value)
        {
            Writer.Write(value);
        }

        public void WriteUInt32(uint value)
        {
            this.Writer.Write(value);
        }

#if DEBUG
        public bool HasSheetId(ushort sheetId)
        {
            var context = BiffWriterWorkbookContext.Current;
            if (context == null)
                return true;
            return context.HasSheetId(sheetId);
        }
#endif
    }
}